package link;

import java.util.HashMap;
import java.util.List;

public class leetCode82_deleteDuplicates {
    public static void main(String[] args) {
        ListNode a = new ListNode(1);
        a.next = new ListNode(2);
        a.next.next = new ListNode(3);
        a.next.next.next = new ListNode(3);
        a.next.next.next.next = new ListNode(4);
        a.next.next.next.next.next = new ListNode(4);
        a.next.next.next.next.next.next = new ListNode(5);
        leetCode82_deleteDuplicates b = new leetCode82_deleteDuplicates();
        b.deleteDuplicates(a);
    }
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null) return null;
        ListNode pre = new ListNode(-1);
        pre.next = head;
        ListNode cur = pre;
        while (cur.next != null && cur.next.next != null){
            if(cur.next.val == cur.next.next.val){
                int val = cur.next.val;
                while ( cur.next != null && cur.next.val == val){
                    cur.next = cur.next.next;
                }
            }else{
                cur = cur.next;
            }
        }
        return pre.next;

    }

    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
